package com.itsc.dao;

import java.util.List;

import org.hibernate.Query;

import com.itsc.entities.Role;
import com.itsc.util.page.Page;

@SuppressWarnings("unchecked")
public class RoleDao extends BaseDao<Role>{

	public boolean checkRole(String name){
		Boolean flag = false;
		String hql = "from Role where role_name=?";
		Query query = getSession().createQuery(hql);
		query.setString(0, name);
		List<Role> roleList = query.list();
		if(roleList.size()==0){
			flag = true;
		}
		return flag;
	}
	
	public List<Role> search(String searchname, Page page) {
		searchname = searchname==null?"":searchname;
		String hql = "from Role where role_name like ?";
		Query query = getSession().createQuery(hql);
		query.setString(0, "%" + searchname + "%");
		if (page != null) {
			query.setFirstResult(page.getBeginIndex());
			query.setMaxResults(page.getPageSize());
		}
		List<Role> list = query.list();
		return list;
	}
	
}
